import {ModalForm, ProFormText, ProFormSelect} from "@ant-design/pro-components";
import {AutoReplyVO} from "@/services/AutoReplyService";
import {useRef, useState} from "react";
import {ProFormInstance} from "@ant-design/pro-form/lib";
import {RequestOptionsType} from "@ant-design/pro-utils";
import {useModel, useSnapshot} from "@@/exports";
import {AutoReplyModel} from "@/models/autoReply";


export interface AutoReplyUpdateModalProps {
    onFinish: (formData: any) => Promise<boolean | void>;
}

const AutoReplyUpdateModal = (props: AutoReplyUpdateModalProps) => {
    let {getDictList} = useModel("dict");
    let autoReplyState = useSnapshot(AutoReplyModel.state);
    let {actions: autoReplyActions} = AutoReplyModel
    const formRef = useRef<ProFormInstance>()
    return <>
        <ModalForm
            key={autoReplyState.autoReply?.id || -1}
            formRef={formRef}
            title={autoReplyState.autoReply ? "修改自动回复" : "添加自动回复"}
            open={autoReplyState.updateModalState}
            initialValues={autoReplyState.autoReply}
            onFinish={props.onFinish}
            onOpenChange={autoReplyActions.setUpdateModalState}
            >
            <ProFormText
                    label="id"
                    name="id"
                    hidden
            />


            <ProFormText
                    label="关键字"
                    name="keyword"
                    rules={[{required: true, message: "请填写关键字"}]}
            />


            <ProFormSelect
                    label="匹配类型"
                    name="matchType"
                    request={async () => getDictList('auto_reply_match_type') as RequestOptionsType[]}
                    rules={[{required: true, message: "请选择匹配类型"}]}
                />


            <ProFormText
                    label="标签"
                    name="tagIds"
            />


            <ProFormSelect
                    label="回复类型"
                    name="replyType"
                    request={async () => getDictList('mp_message_type') as RequestOptionsType[]}
                />


            <ProFormText
                    label="回复内容"
                    name="replyContent"
            />


            <ProFormText
                    label="通知渠道"
                    name="notifyIds"
            />


            <ProFormText
                    label="通知内容"
                    name="notifyText"
            />


            <ProFormText
                    label="租户id"
                    name="tenantId"
                    rules={[{required: true, message: "请填写租户id"}]}
            />


        </ModalForm>
    </>
}

export default AutoReplyUpdateModal
